import datetime


class DateTimeTools(object):
    @staticmethod
    def addDay(dateparam, number):
        dateparam = datetime.datetime.strptime(dateparam, "%Y-%m-%d").date()    # 获取当前时间变量
        newDate = dateparam + datetime.timedelta(days=number)   # 计算加减天数
        return newDate

    @classmethod
    def addHour(cls, dateparam, number):
        try:
            newHours = datetime.datetime.strptime(dateparam, "%Y-%m-%d %H:%M:%S") +\
                       datetime.timedelta(hours=number)
            return newHours
        except ValueError as e:
            print(e)
            # raise ValueError("日期格式需要是%Y-%m-%d %H:%M:%S")


if __name__ == "__main__":
    newDate = DateTimeTools.addDay(dateparam="2024-03-27", number=5)
    newHour = DateTimeTools.addHour(dateparam="2024-03-27 00:00:00", number=5)
    print(newDate)
    print(newHour)
